package top.songxs.yygh.common.exp;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import top.songxs.yygh.common.result.R;

@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    public R handleException(Exception e){
        return R.error().message("出现了全局异常"+e.getMessage());
    }

    @ExceptionHandler(value = DiyException.class)
    public R handleDiyException(DiyException e){
        log.error(e.getMsg()); //这是一条error级别的日志
        return R.error().message("出现了自定义异常"+e.getMsg());
    }


    @ExceptionHandler(value = NullPointerException.class)
    public R handleNullPointerException(NullPointerException e){
        return R.error().message("出现了空指针异常"+e.getMessage());
    }


































}
